#coding:utf8
import pika
import json

file=open("meizuyz.csv")

rabbitmq_host='may'
rabbitmq_queue_name='pns-push.notification.queue'
notification = {
    'title':'你听过《罗辑思维》吗？',
    'message':'184集罗辑思维脱口秀等你来听>>',
    'msgId':' ',
    'albumId':239463,
    'clientOpenType':13

}
deviceIdMap={}
sendNotification = {'deviceIdMap':deviceIdMap,
                  'messageType':9}

connection = pika.BlockingConnection(pika.ConnectionParameters(
               rabbitmq_host))
channel = connection.channel()
channel.queue_declare(queue=rabbitmq_queue_name, durable=True)


while 1:
    line = file.readline().strip()
    # 如果line为空,跳出循环
    if not line:
        break
        pass
    if len(line) > 0:
        print line
        deviceIdMap.clear()
        deviceIdMap[line] = notification
        json_body = json.dumps(sendNotification)
        print json_body
        # 因为发送的是json字符串,必须说明是文本类型
        channel.basic_publish(exchange='', routing_key=rabbitmq_queue_name, body=json_body,
                              properties=pika.BasicProperties(
                                  content_type="text/plain"
                              ))

print 'end'
connection.close()